  function [irfmat,irfst]=irfgensys(G1,impact,zmat,snumber,nper,sdsh)
% =========================================================================
% function irfmat=irfgensys(G1,impact,zmat,snumber,nper,sdsh)
% 
% Compute impulse responses for the output from gensys.m 
% System solution is of the form 
% y(t)=G1*y(t-1)+IMPACT*e(t) 
% yobs(t)=zmat*y(t) where 
% yobs(t) is vector of observables  
% y(t)    is vector of states 
%
% Inputs 
% ------
% G1 and impact  Output matrices from gensys 
% zmat           Maps the state vector into observables 
% snumber        Shock Number [column of impact] 
% nper           Number of periods 
% sdsh           optional input argument to make shocks correspond to one standard deviation 
% Output 
% -------
% irfmat        [nobs x nper ] matrix of impulse responses for observables  
% irfst         [ny   x nper ] matrix of impulse responses for states 
% Alejandro Justiniano 5/27/03 
% 5/29/03 Allow to compute a one SD shock by adding the sdsh output 
% Last 6/15/05
% =========================================================================
irfmat=zeros(size(zmat,1),nper+1);
irfst=zeros(size(G1,1),nper+1); 
if nargin == 5 || sdsh ==0
    irfst(:,1)=impact(:,snumber);
else
    if sdsh < 0
        error('Standard Deviation must be positive')
    end
    irfst(:,1)=sdsh*impact(:,snumber);
end
irfmat(:,1)=zmat*irfst(:,1);
for ii=2:nper+1; 
    irfst(:,ii)=G1*irfst(:,ii-1); 
    irfmat(:,ii)=zmat*irfst(:,ii);  
end